package com.example.demo.threads;

import com.example.demo.mp.entity.User;
import com.example.demo.mp.service.UserService;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;

@Slf4j
public class BatchSqlThread implements Runnable {
    @Setter
    @Getter
    private CountDownLatch countDownLatch;
    @Setter
    @Getter
    private UserService userService;
    @Setter
    @Getter
    private List<User> userList;

    @Override
    public void run() {
        log.info("线程开始跑...");
        boolean result = getUserService().saveBatch(getUserList());
        log.info("当前线程:{},countDown:{},batch结果:{}", Thread.currentThread().getName(), countDownLatch.getCount(), result);
        getCountDownLatch().countDown();
        log.info("线程结束...");
    }
}
